package com.ruoyi.base.enums.unit;

import lombok.Getter;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Objects;

/**
 * 项目类型
 *
 * @author lcf
 */
public enum UnitEnum {
    /**
     * 个
     */
    ge(1, "个", BigDecimal.valueOf(1)),
    /**
     * 千个
     */
    qg(2, "千个", BigDecimal.valueOf(1000)),
    /**
     * 百万个
     */
    bwg(3, "百万个", BigDecimal.valueOf(1000000));

    @Getter
    private int code;
    @Getter
    private String name;
    @Getter
    private BigDecimal amount;

    UnitEnum(int code, String name, BigDecimal amount) {
        this.code = code;
        this.name = name;
        this.amount = amount;
    }

    public static UnitEnum ofCode(Integer code) {
        return Arrays.stream(UnitEnum.values()).filter(x -> Objects.equals(code, x.getCode())).findAny().orElse(null);
    }
}
